<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="taskList" @selection-change="handleSelectionChange">
      <el-table-column label="等级ID" align="center" prop="levelId" />
      <el-table-column label="等级名称" align="center" prop="levelName" />
      <el-table-column label="等级图标" align="center" prop="icon">
        <template slot-scope="scope">
          <el-image :src="requestUrl + scope.row.icon" fit="fill" style="width: 146px; height: 146px"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="最小邀请人数" align="center" prop="minDirectCnt" />
      <el-table-column label="最大邀请人数" align="center" prop="maxDirectCnt" />
      <el-table-column label="购买价格" align="center" prop="buyPrice" />
      <el-table-column label="释放分配比率" align="center" prop="assignPer" />
      <el-table-column label="兑换手续费比率" align="center" prop="exchangeFeePer" />
      <el-table-column label="划转手续费比率" align="center" prop="transferFeePer" />
      <el-table-column label="交易手续费比率" align="center" prop="tradeFeePer" />
      <!--      <el-table-column label="直推是否会员" align="center" prop="directVipFlag">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span v-if="scope.row.directVipFlag==0">否</span>-->
      <!--          <span v-if="scope.row.directVipFlag==1">是</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="是否能购买" align="center" prop="buyFlag">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span v-if="scope.row.buyFlag==0">否</span>-->
      <!--          <span v-if="scope.row.buyFlag==1">是</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="价格" align="center" prop="buyPrice"/>-->
      <!--      <el-table-column label="提现手续费" align="center" prop="withdrawFeePer">-->
      <!--      </el-table-column>-->
      <el-table-column label="描述说明" align="center" prop="description" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleView(scope.row)"
            v-hasPermi="['admin:taskLevel:list']">编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 用户明细 -->
    <el-dialog :title="title" :visible.sync="detailDialogTableVisible" width="700px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="最小直推人数">
          <el-input-number v-model="form.minDirectCnt" />
        </el-form-item>
        <el-form-item label="最大直推人数">
          <el-input-number v-model="form.maxDirectCnt" />
        </el-form-item>
        <el-form-item label="购买价格">
          <el-input-number v-model="form.buyPrice" />
        </el-form-item>
        <el-form-item label="释放分配比率">
          <el-input-number v-model="form.assignPer" />
        </el-form-item>
        <el-form-item label="兑换手续费比率">
          <el-input-number v-model="form.exchangeFeePer" />
        </el-form-item>
        <el-form-item label="划转手续费比率">
          <el-input-number v-model="form.transferFeePer" />
        </el-form-item>
        <el-form-item label="交易手续费比率">
          <el-input-number v-model="form.tradeFeePer" />
        </el-form-item>
        <el-form-item label="等级图标" prop="icon">
          <imageUpload :limit="1" :file-size="3" v-model="form.icon" />
        </el-form-item>
        <el-form-item label="描述">
          <editor v-model="form.description" :height="350" />
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getTaskLevelList, updateTaskLevel } from "@/api/admin/task";
export default {
  name: "Task",
  data () {
    return {
      requestUrl: this.$img.requestUrl,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户领取任务表格数据
      taskList: [
        {
          directVipFlag: 0,
          buyFlag: 1,
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // levelName: ''
      },
      form: {},
      detailDialogTableVisible: false,
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询用户领取任务列表 */
    getList () {
      this.loading = true;
      getTaskLevelList(this.queryParams).then((response) => {
        this.taskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 详细按钮操作 */
    handleView (row) {
      this.detailDialogTableVisible = true;
      this.form = { ...row };
    },
    // 取消按钮
    cancel () {
      this.detailDialogTableVisible = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {};
      this.resetForm("form");
    },
    submitForm () {
      updateTaskLevel(this.form).then((res) => {
        if (res.code === 200) {
          this.msgSuccess(res.msg);
          this.getList();
          this.cancel();
        }
      });
    },
  },
};
</script>
<style>
.task_row {
  display: flex;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
}

.task_item {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 25%;
  padding-top: 10px;
  padding-bottom: 10px;
}

.opacity {
  opacity: 0.4;
  background: #e5e5e5;
}

.task_item img {
  margin-bottom: 3px;
  display: block;
}

.user_task_row {
  display: flex;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
}

.user_task_item {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 25%;
  padding-top: 10px;
  padding-bottom: 10px;
}

.opacity {
  opacity: 0.4;
  background: #e5e5e5;
}

.user_task_item img {
  margin-bottom: 3px;
  display: block;
}
</style>
